import { MockMethod } from 'vite-plugin-mock';
import { Random } from 'mockjs';
import { resultPageSuccess, resultSuccess } from '../_util';
import { pick } from 'lodash-es';

const pinsInfo = (() => {
  const result: any[] = [];
  for (let index = 0; index < 100; index++) {
    result.push({
      id: index,
      title: '@cparagraph()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
    });
  }
  return result;
})();

const articlesInfo = (() => {
  const result: any[] = [];
  for (let index = 0; index < 100; index++) {
    result.push({
      id: index,
      title: '@ctitle()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
    });
  }
  return result;
})();

const cardData = {
  all_article: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_article_collect: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_article_comment: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_article_digg: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_article_display: {
    cnt: '@natural(0, 1000)',
    'than_before|1': [Random.integer(-100, 0), Random.integer(0, 100)],
  },
  all_article_view: {
    cnt: '@natural(0, 1000)',
    'than_before|1': [Random.integer(-100, 0), Random.integer(0, 100)],
  },
  all_follower: {
    cnt: '@natural(0, 10000)',
    'than_before|1': [Random.integer(-100, 0), Random.integer(0, 100)],
  },
  all_short_msg: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_short_msg_digg: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  all_short_msg_comment: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  incr_active_follower: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  incr_do_follower: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  incr_undo_follower: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
  incr_follower: {
    cnt: '@natural(0, 100)',
    'than_before|1': [Random.integer(-10, 0), Random.integer(0, 10)],
  },
};

const articleDraftsInfo = (() => {
  const result: any[] = [];
  for (let index = 0; index < 50; index++) {
    result.push({
      id: index,
      title: '@ctitle()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
    });
  }
  return result;
})();

export default [
  {
    url: '/basic-api/creator/content/queryPinList',
    timeout: 500,
    method: 'post',
    response: ({ body }) => {
      const { current = 1, pageSize = 10, status = 0 } = body;

      return resultPageSuccess(
        current,
        pageSize,
        body && Reflect.has(body, 'status')
          ? pinsInfo.filter((info) => info.status === status)
          : pinsInfo,
      );
    },
  },
  {
    url: '/basic-api/creator/content/queryArticleList',
    timeout: 500,
    method: 'post',
    response: ({ body }) => {
      const { current = 1, pageSize = 10 } = body;

      return resultPageSuccess(current, pageSize, articlesInfo);
    },
  },
  {
    url: '/basic-api/author_center/data/card',
    timeout: 500,
    method: 'post',
    response: ({ body }) => {
      const { datas } = body;

      return resultSuccess(pick(cardData, datas));
    },
  },
  {
    url: '/basic-api/article_drafts/list_by_user',
    timeout: 500,
    method: 'post',
    response: ({ body }) => {
      const { current = 1, pageSize = 10 } = body;
      return resultPageSuccess(current, pageSize, articleDraftsInfo);
    },
  },
] as MockMethod[];
